package com.cskaoyan.mall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.product.dto.TrademarkDTO;
import com.cskaoyan.mall.product.dto.TrademarkPageDTO;
import com.cskaoyan.mall.product.query.TrademarkParam;
import com.cskaoyan.mall.product.service.TrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product")
public class AdminBaseTrademarkController {
    @Autowired
    TrademarkService trademarkService;
    @GetMapping("/baseTrademark/{pageNum}/{pageLimit}")
    public Result baseTrademark(@PathVariable int pageNum,@PathVariable int pageLimit){
        //这里主要是查询列表，然后加个分页
        TrademarkPageDTO trademarkPageDTO = trademarkService.getPage(new Page<>(pageNum, pageLimit));
        return Result.ok(trademarkPageDTO);
    }

    @PostMapping("/baseTrademark/save")
    public Result save(@RequestBody TrademarkParam trademarkParam){
        trademarkService.save(trademarkParam);
        return Result.ok();
    }

    @GetMapping("/baseTrademark/get/{id}")
    public Result baseTrademark(@PathVariable long id){
        TrademarkDTO trademarkDTO = trademarkService.getTrademarkByTmId(id);
        return Result.ok(trademarkDTO);
    }

    @PutMapping("/baseTrademark/update")
    public Result update(@RequestBody TrademarkParam trademarkParam ){
        trademarkService.updateById(trademarkParam);
        return Result.ok();
    }

    @DeleteMapping("/baseTrademark/remove/{tradeMarkId}")
    public Result remove(@PathVariable Long tradeMarkId ){
        trademarkService.removeById(tradeMarkId);
        return Result.ok();
    }
}
